home *** CD-ROM | disk | FTP | other *** search
- Path: tko.dec.com!diamond
- From: diamond@tko.dec.com (Norman Diamond)
- Newsgroups: comp.std.c
- Subject: Re: size_t
- Date: 5 Feb 1996 03:17:14 GMT
- Organization: Digital Equipment Corporation Japan , Tokyo
- Message-ID: <4f3srq$9ns@usenet.pa.dec.com>
- References: <DM48Fv.5Ay@novice.uwaterloo.ca>
- Reply-To: diamond@jrdv04.enet.dec-j.co.jp (Norman Diamond)
- NNTP-Posting-Host: jit533.tko.dec.com
-
- In article <DM48Fv.5Ay@novice.uwaterloo.ca>, lhuang@swen3.uwaterloo.ca (Larry Huang) writes:
- >I was writing some code to manage a table the other day. I used
- >a size_t to keep track of the size of the table, and I defined a
- >macro SIZE_T_MAX as (size_t)(-1) for making sure the table doesn't
- >get too large. Then I suddenly realize that it may not work as
- >I thought. An implementation can restrict the size of a data
- >object to 32 K (is my memory correct here?), but the value of
- >(size_t)(-1) can at the same time be very large (e.g. ULONG_MAX).
-
- True.
-
- >So my question is, is there a way to find out what the maximum
- >allowable size of a data object is under an implementation?
-
- Statically, I think not. You can declare one array of 32767 chars and
- hope that your program is the lucky one that some implementation will
- translate and execute. If you push any farther then entropy reverses.
-
- Dynamically, you can try malloc'ing (size_t)(-1), if it doesn't work
- then try (size_t)(-2), etc. (Notice that a binary search might not
- accomplish the actual maximum result, because if the first successful
- malloc is 80% of the actual maximum and then you free it, I don't think
- the implementation is required to coalesce the free spaces.)
- --
- << If this were the company's opinion, I would not be allowed to post it. >>
- "I paid money for this car, I pay taxes for vehicle registration and a driver's
- license, so I can drive in any lane I want, and no innocent victim gets to call
- the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
-